cmake_minimum_required(VERSION 3.16)

project(atmosphere VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(QT_VERSION_MAJOR 6)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj")

#find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Charts)
find_package(Qt6 REQUIRED COMPONENTS Sql)
find_package(Qt6 REQUIRED COMPONENTS Concurrent)
find_package(Qt6 REQUIRED COMPONENTS SerialPort)

#set(CMAKE_TOOLCHAIN_FILE  D:\src\vcpkg\scripts\buildsystems\vcpkg.cmake)
#set(CMAKE)
add_subdirectory(protocol/gRPC)

set(PROJECT_SOURCES
        main.cpp
        mainwindow.cpp
        mainwindow.h
        mainwindow.ui
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(atmosphere
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
        resource.qrc
        dataBase/connection.cpp dataBase/connection.h
        form/device/groundweatherstationform.cpp form/device/groundweatherstationform.h form/device/groundweatherstationform.ui form/device/mscatteringlidarform.cpp form/device/mscatteringlidarform.h form/device/mscatteringlidarform.ui
        form/device/solarradiometer2form.cpp form/device/solarradiometer2form.h form/device/solarradiometer2form.ui form/device/visibilityform.cpp form/device/visibilityform.h form/device/visibilityform.ui form/device/widgetdeviceform.cpp
        form/device/widgetdeviceform.h form/device/widgetdeviceform.ui
        form/Inversion/widgetinversionform.cpp form/Inversion/widgetinversionform.h form/Inversion/widgetinversionform.ui
        form/log/widgetlogform.cpp form/log/widgetlogform.h form/log/widgetlogform.ui
        form/show/circleprogressbar.cpp form/show/circleprogressbar.h form/show/groundweatherstationdisplayform.cpp form/show/groundweatherstationdisplayform.h
        form/show/groundweatherstationdisplayform.ui form/show/mscatteringlidardisplayform.cpp form/show/mscatteringlidardisplayform.h form/show/mscatteringlidardisplayform.ui
        form/show/solarradiometerdisplayform.cpp form/show/solarradiometerdisplayform.h form/show/solarradiometerdisplayform.ui form/show/visibilitydisplayform.cpp form/show/visibilitydisplayform.h
        form/show/visibilitydisplayform.ui form/show/widgetshowcontrolform.cpp form/show/widgetshowcontrolform.h form/show/widgetshowcontrolform.ui
        form/sys/widgetsysform.cpp form/sys/widgetsysform.h form/sys/widgetsysform.ui
        protocol/groundweatherstationprotocol.h protocol/mscatteringlidarprotocol.h protocol/solarradiometer2protocol.h protocol/solarradiometerprotocol.h protocol/visibilityprotocol.h
        form/device/lidarclient.h form/device/lidarclient.cpp
        form/gloab/globalobserver.h form/gloab/globalobserver.cpp
        form/Inversion/inversionargument.h form/Inversion/inversionargument.cpp
        form/gloab/mymessagebox.h form/gloab/mymessagebox.cpp
        form/log/QsLog/QsLog.cpp form/log/QsLog/QsLog.h form/log/QsLog/QsLogDest.cpp form/log/QsLog/QsLogDest.h form/log/QsLog/QsLogDestConsole.cpp form/log/QsLog/QsLogDestConsole.h
        form/log/QsLog/QsLogDestFile.cpp form/log/QsLog/QsLogDestFile.h form/log/QsLog/QsLogDestFunctor.cpp form/log/QsLog/QsLogDestFunctor.h form/log/QsLog/QsLogDisableForThisFile.h
        form/log/QsLog/QsLogLevel.h
        form/sys/initdatabase.cpp form/sys/initdatabase.h form/sys/initdatabase.ui
     )
# Define target properties for Android with Qt 6 as:
#    set_property(TARGET atmosphere APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
#                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
    if(ANDROID)
        add_library(atmosphere SHARED
            ${PROJECT_SOURCES}
        )
# Define properties for Android with Qt 5 after find_package() calls as:
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(atmosphere
            ${PROJECT_SOURCES}
        )
    endif()
endif()

INCLUDE_DIRECTORIES(form/device/)
INCLUDE_DIRECTORIES(form/Inversion/)
INCLUDE_DIRECTORIES(form/log/)
INCLUDE_DIRECTORIES(form/show/)

target_link_libraries(atmosphere PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Charts)
target_link_libraries(atmosphere PRIVATE Qt6::SerialPort)
target_link_libraries(atmosphere PRIVATE Qt6::Sql)
target_link_libraries(atmosphere PRIVATE Qt6::Concurrent)
target_link_libraries(atmosphere PRIVATE gRPC_Obj)

#find_library(DEEPINSIGHT_LIBRARY deepinsight HINT D:/QtSpace/xiguangsuo3.0/atmosphere/lib/)
#target_compile_definitions(atmosphere PRIVATE DLLTEST_EXPORTS)
#link_directories(D:/QtSpace/xiguangsuo3.0/atmosphere/lib/)

#TARGET_LINK_LIBRARIES(atmosphere PRIVATE ${DEEPINSIGHT_LIBRARY})

install(DIRECTORY D:/QtSpace/xiguangsuo3.0/atmosphere/lib/
        DESTINATION ${PROJECT_BINARY_DIR}/bin)



# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
#if(${QT_VERSION} VERSION_LESS 6.1.0)
#  set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.atmosphere)
#endif()
set_target_properties(atmosphere PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

include(GNUInstallDirs)
install(TARGETS atmosphere
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(atmosphere)
endif()
